home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / dsiic2.zip / MAKEHELP.C < prev    next >
C/C++ Source or Header  |  1991-07-15  |  4KB  |  173 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   MAKEHELP.C   ***************************/
  4.  
  5. /*
  6. link with :
  7. hlp_menu.c
  8. hlp_io.c
  9. */
  10.  
  11. #include "mydef.h"
  12. #include "help.h"
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15.  
  16. struct hlp help;
  17.  
  18.  
  19. int start(int argc, char *argv[])      /* start is the entry point */
  20. {
  21. extern struct hlp help;
  22. extern struct screen_structure scr;
  23. extern struct window_structure w[];
  24.  
  25. cls();
  26.  get_name(help.filename);       /* select a filename */
  27.  if(help.filename[0]=='\0'){    /* if none selected */
  28.   win_delete_top();
  29.   cls();
  30.   print(1,1,"A file must be selected.");
  31.   exit(1);
  32.  }
  33.  
  34.   /* make the three windows */
  35.  help.edit=  win_make(2,3,help.width,help.height,STD_FRAME,
  36.                      "Edit: Then 'Esc' ",scr.normal,scr.normal);
  37.  help.menu=  win_make(1,1,80,1,NO_FRAME,"",scr.inverse,scr.inverse);
  38.    cursor(NO_CURSOR);
  39.  help.status= win_make(1,25,80,1,NO_FRAME,"",scr.inverse,
  40.                        scr.inverse);
  41.    cursor(NO_CURSOR);
  42.   main_menu();    /* call the first menu */
  43.  
  44. /* clean up to exit */
  45.   win_delete (help.edit);
  46.   win_delete (help.menu);
  47.   win_delete (help.status);
  48.  
  49. return (0);
  50. }
  51.  
  52. /* this function allows editing of the help window */
  53.  
  54. void edit(int x, int y)
  55. {
  56. extern struct screen_structure scr;
  57. extern struct window_structure w[];
  58.  
  59. char string[2];
  60. char ch,ext;
  61.  
  62.  scr.current=win_what_attr(help.edit);
  63.  ch= 0;
  64.     while(ch != ESCAPE) {       /* read while key not 'Esc' */
  65.      ch=0;ext=0;
  66.      get_key(&ch,&ext);
  67.  
  68.       /* break while{} loop if PgUp or PgDn */
  69.       if(ext==PGUP || ext==PGDN) break;  
  70.  
  71.        if(ch  > 31){                /* if character */
  72.         string[0]=ch;string[1]='\0';/* build a string */
  73.         print_here(string);         /* put on screen */
  74.        x++;                         /* increment cursor location */
  75.       }
  76.       else{
  77.         switch (ext){              /* if cursor key */
  78.          case UP:y-- ;break;       /* act accordingly*/
  79.          case DOWN:y++ ;break;
  80.          case LEFT:x-- ;break;
  81.          case RIGHT:x++ ;break;
  82.          case HOME:x=1 ;break;
  83.          case END:x=scr.right-scr.left+1;break;
  84.         }
  85.      } /* end else */
  86.        if (ch==BACKSPACE)x--;
  87.        if(ch==RETURN){
  88.          x=1;
  89.          y++;
  90.        }
  91.  
  92.        /* the following code adjusts the cursor within the window */
  93.  
  94.        if(scr.left+x-1<scr.left){  /* too far left */
  95.           x=scr.right-scr.left+1;
  96.           y--;
  97.         }
  98.  
  99.        if(scr.left+x-1>scr.right){x=1;y++;};    /* goto next line */
  100.        if(scr.top+y-1<scr.top)y=scr.bottom-scr.top+1;
  101.        if(scr.top+y-1>scr.bottom)y=1;
  102.  
  103.          if (ch=='\b') print(x,y," ");
  104.          goxy(x,y);
  105.  
  106.    } /* end while ch!=27 */
  107.  
  108.    x=1;y=1;
  109.    goxy(x,y);
  110. }
  111.  
  112. /* this function creates an input screen for entry
  113.    of new help screen sizes */
  114.  
  115. int get_size()
  116. {
  117. extern struct screen_structure scr;
  118. extern struct window_structure w[];
  119.  
  120. char width[3]="";
  121. char height[3]="";
  122. int in_window;
  123. int return_code;
  124.  
  125. struct in_struc in_scrn[3]= {
  126.  
  127. /*
  128. X   Y  Label name          Ptr   Length  Label-color  Field color */
  129.  
  130. 1,  3, "Width  (10-78): ", NULL, 2,      WHITE,BLACK, BLACK,WHITE,
  131. 1,  4, "Height (5-23):  ", NULL, 2,      WHITE,BLACK, BLACK,WHITE,
  132. 0   /* terminator */
  133. };
  134.        in_scrn[0].ptr =width;
  135.        in_scrn[1].ptr =height;
  136.  
  137.   cls();
  138.   in_window= win_make(1,1,78,5,STD_FRAME,"",scr.normal,scr.normal);
  139.  
  140.   print(1,1,"PLEASE ENTER HELP SCREEN SIZE:");
  141.   return_code = input(in_scrn);
  142.   if(return_code==ESCAPE)
  143.      return(return_code);
  144.   else{
  145.        help.width=atoi(width);       /* convert to integer */
  146.        help.height=atoi(height);
  147.       }
  148.   win_delete(in_window);
  149.   return(0);
  150. }
  151.  
  152.  
  153. /* val_field() is used by input routine to check validity of data */
  154.  
  155. int val_field( char *string,int length,int field_number)
  156. {
  157. int value;
  158.  
  159.  /* in this demo "length" is not used */
  160.  
  161.  
  162.  int age;
  163.  
  164.  switch (field_number){
  165.   case 0: value=atoi(string);         /* convert string to integer */
  166.           if (value <10 || value >78) return(REDO);
  167.            break;
  168.   case 1: value=atoi(string);         /* convert string to integer */
  169.           if (value <5 || value >23) return(REDO);
  170.  }
  171. return (OK);
  172. }
  173.